package com.cet.qz.unit01.chapter1_3;

import edu.princeton.cs.algs4.StdOut;

import java.io.File;

/**
 * @program: algorithm
 * @description: 文件列表
 * @author: 陈恩涛
 * @create: 2021-04-24 21:33
 **/
public class Qz1_3_43 {

    private static Queue<String> queue = new Queue<>();

    public static void listAllFiles(String path, int dep){
        File f = new File(path);
        File[] files = f.listFiles();
        if (files != null &&files.length > 0) {
            for (File file : files) {
                String tab = "";
                int times = dep;
                while (times > 0) {
                    tab = tab + "|\t";
                    times--;
                }
                queue.enqueue(tab + "|-- " +file.getName());
                if (file.isDirectory()) {
                    listAllFiles(file.getAbsolutePath(), dep + 1);
                }
            }
        }
    }

    public static void listAllFiles(String path) {
        queue.enqueue(".");
        listAllFiles(path,0);
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        String path = "C:\\Users\\CET\\Desktop";
        StdOut.println(path);
        listAllFiles(path);
        for (String s : queue) {
            System.out.println(s);
        }

    }

}

/*
 *
 * .
 * |-- anaconda-ks.cfg
 * |-- Desktop
 * |-- Documents
 * |-- Downloads
 * |-- logs
 * |   |-- arthas
 * |   |   |-- arthas.log
 * |   |   `-- classdump
 * |   |       `-- sun.misc.Launcher$AppClassLoader-70dea4e
 * |   |           `-- demo
 * |   |               `-- MathGame.class
 * |   `-- arthas-cache
 * |       `-- result.log
 * |-- Music
 * |-- Pictures
 * |-- Public
 * |-- Templates
 * |-- Videos
 * `-- workspace
 *     |-- nohup.out
 *     `-- spring-session-bu-0.0.1-SNAPSHOT.jar
 *
 *
 */


